package cn.wolfcode.wolf2w.service.impl;

import cn.wolfcode.wolf2w.domain.Spots;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.redis.service.IRedisService;
import cn.wolfcode.wolf2w.repository.SpotsRepository;
import cn.wolfcode.wolf2w.service.ISpotsService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.DBHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class SpotsServiceImpl implements ISpotsService {

    @Autowired
    private SpotsRepository spotsRepository;


    @Autowired
    private MongoTemplate template;

    @Override
    public void insert(Spots spots) {
        spotsRepository.insert(spots);
        spots.setId(null);
    }

    @Override
    public void delete(String id) {
        spotsRepository.deleteById(id);
    }

    @Override
    public void update(Spots spots) {
        spotsRepository.save(spots);
    }

    @Override
    public Spots selectOne(String id) {
        Spots spots = spotsRepository.findById(id).orElse(null);
        //Spots spots = byId.get();
        return spots;
    }

    @Override
    public List<Spots> selectAll() {
        List<Spots> all = spotsRepository.findAll();
        return all;
    }


}
